package com.xuzhijie.pms.exception;

import cn.hutool.json.JSONUtil;
import com.xuzhijie.pms.common.Constants;
import com.xuzhijie.pms.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;
import java.sql.SQLSyntaxErrorException;

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(PmsServerException.class)
    @ResponseBody
    public Result PmsServerExceptionHandle(PmsServerException pse){
        log.info("捕获异常");
        pse.printStackTrace();
        return  Result.error(pse.getCode(), pse.getMessage());
    }

    @ExceptionHandler(SQLException.class)
    @ResponseBody
    public Result SQLExceptionHandle(SQLException se){
        log.info("捕获异常: Sql出错");
        se.printStackTrace();
        return Result.error(Constants.SYSTEM_ERROR,"业务繁忙");
    }

}
